package com.htkj.demo.adapter

import android.content.Context
import android.database.DataSetObserver
import android.graphics.Color
import android.view.View
import android.view.ViewGroup
import android.widget.SpinnerAdapter
import android.widget.TextView
import com.htkj.demo.bean.SpinnerData


class MySpinnerAdapter(val mContext:Context,var list: MutableList<SpinnerData>?) : SpinnerAdapter {
    override fun registerDataSetObserver(observer: DataSetObserver?) {

    }

    override fun unregisterDataSetObserver(observer: DataSetObserver?) {

    }

    override fun getCount(): Int {
        return list?.size?:0;
    }

    override fun getItem(position: Int): Any? {
        return if(getCount()>position) list!![position] else null
    }

    override fun getItemId(position: Int): Long {
       return  position.toLong();
    }

    override fun hasStableIds(): Boolean {
        return false
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
       val sequenc = list!![position]
        val textView = TextView(mContext)
        textView.textSize = 10f
        textView.text = sequenc.name
        textView.setPadding(20,10,10,10)
        if(sequenc.id==-1L){
            textView.setTextColor(Color.parseColor(if(sequenc.id==-1L) "#666666" else "#999999"))
        }
        return textView
    }

    override fun getItemViewType(position: Int): Int {
        return 1
    }

    override fun getViewTypeCount(): Int {
        return 1
    }

    override fun isEmpty(): Boolean {
        return false
    }

    override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup?): View {
        val textView = TextView(mContext)
        textView.textSize = 10f
        textView.text = list!![position].name
        textView.setPadding(20,10,10,10)
        return textView
    }
}